package com.cstor.liang.mapper;

import com.cstor.liang.pojo.entity.Region;
import com.cstor.liang.pojo.other.RegionJo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RegionMapper extends GoMapper<Region> {

	@Select(" SELECT id, province AS name FROM region_info WHERE stage = 1 ")
	List<RegionJo> listProvince();

	@Select(" SELECT id, city AS name FROM region_info WHERE stage = 2 " +
			" AND region_code LIKE #{prefixCode} ")
	List<RegionJo> listCity(String prefixCode);

	@Select(" SELECT id, county AS name FROM region_info WHERE stage = 3 " +
			" AND region_code LIKE #{prefixCode} ")
	List<RegionJo> listCounty(String prefixCode);

	@Select(" SELECT id, street AS name FROM region_info WHERE stage = 4 " +
			" AND region_code LIKE #{prefixCode} ")
	List<RegionJo> listStreet(String prefixCode);

	@Select(" SELECT region_code AS regionCode FROM region_info WHERE id = #{regionId} ")
	String getRegionCode(Long regionId);

	@Select(" SELECT id, region_code AS regionCode, county, street, stage FROM region_info " +
			" WHERE region_code LIKE #{prefixCode} ")
	List<Region> listCountyAndStreet(String prefixCode);
}
